﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@section header{
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/shris/js/vue.js"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/shris/css/element-index.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/shris/js/element-index.js"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/shris/js/axios.js"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/shris/css/DeviceManage/index.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/shris/css/ShellManage/shell.css"))
}
<div class="container-div" id="deviceManage_Manipulator-vue">
    <el-row>
        <el-col :span="10">
            <el-card>
                <div slot="header" class="myhead">
                    <div>机器人数据</div>
                </div>
                <div>
                    <div class="my-p">
                        <div class="my-p-l">状态</div>
                        <div class="my-p-r">{{ rbData.status }}</div>
                    </div>
                    <div class="my-p">
                        <div class="my-p-l">当前报警</div>
                        <div class="my-p-r">{{ rbData.alarm }}</div>
                    </div>
                    <div class="my-p">
                        <div class="my-p-l">工件来源</div>
                        <div class="my-p-r">{{ rbData.fromA }}</div>
                    </div>
                    <div class="my-p">
                        <div class="my-p-l">抓取1</div>
                        <div class="my-p-r">{{ rbData.source1 }}</div>
                    </div>
                    <div class="my-p">
                        <div class="my-p-l">抓取2</div>
                        <div class="my-p-r">{{ rbData.source2 }}</div>
                    </div>
                    <div class="my-p">
                        <div class="my-p-l">放置1</div>
                        <div class="my-p-r">{{ rbData.target1 }}</div>
                    </div>
                    <div class="my-p">
                        <div class="my-p-l">放置2</div>
                        <div class="my-p-r">{{ rbData.target2 }}</div>
                    </div>
                    <div class="my-p">
                        <div class="my-p-l">位置</div>
                        <div class="my-p-r">{{ rbData.address }}</div>
                    </div>
                </div>
            </el-card>
        </el-col>
    </el-row>
    
</div>

<script>
    let app = new Vue({
        el: "#deviceManage_Manipulator-vue",
        data: {
            rbData: {
                status: null,
                alarm: null,
                fromA: null,
                source1: null,
                source2: null,
                target1: null,
                target2: null,
                address: null
            }
        },
        methods: {
            // 获取设备当天的历史状态信息
            GetTodayData() {
                let url = '@Url.Content("~/DeviceManage/DeviceDetail/GetRBData")'
                axios.get(url).then(res => {
                    console.log(res);
                    let result = res.data;
                    if (result != null) {
                        if (result.MStatus != null && result.MStatus[2]) {
                            this.rbData.status = "运行"
                        } else {
                            if (result.Ready) {
                                this.rbData.status = "准备"
                            } else {
                                this.rbData.status = "未准备好"
                            }
                        }
                        if (result.MAlarm1 != null && result.MAlarm1[0]) {
                            this.rbData.alarm = "机器人抓时激光传感器错误";
                        } else {
                            if (result.MAlarm1 != null && result.MAlarm1[1]) {
                                this.rbData.alarm = "机器人放时激光传感器错误";
                            } else {
                                this.rbData.alarm = "";
                            }
                        }
                        
                        this.rbData.fromA = this.getDataDefind("工件来源", result.WorkpieceSource);
                        this.rbData.source1 = this.getDataDefind("抓命令1", result.Grab01)
                        this.rbData.source2 = this.getDataDefind("抓命令2", result.Grab02)
                        this.rbData.target1 = this.getDataDefind("放命令1", result.Put01)
                        this.rbData.target2 = this.getDataDefind("放命令2", result.Put02)
                        this.rbData.address = this.getDataDefind("位置", result.Position)
                    }
                }).catch(err => {
                    console.log(err)
                })
            },
            // 数据定义处理函数
            getDataDefind(tag, value) {
                let result = "";
                switch (tag) {
                    case "工件来源": {
                        switch (value) {
                            case 0: {
                                result = "";
                                break;
                            }
                            case 1: {
                                result = "车床1";
                                break;
                            }
                            case 2: {
                                result = '缓存台1'
                                break;
                            }
                            case 3: {
                                result = "缓存台2"
                                break;
                            }
                            case 4: {
                                result = "车床2"
                                break;
                            }
                            case 5: {
                                result = '缓存台3'
                                break;
                            }
                            case 6: {
                                result = "缓存台4"
                                break;
                            }
                            case 7: {
                                result = "车床3"
                                break;
                            }
                            case 8: {
                                result = '缓存台5'
                                break;
                            }
                            case 9: {
                                result = "缓存台6"
                                break;
                            }
                            case 10: {
                                result = "孔深测量"
                                break;
                            }
                            case 11: {
                                result = '扫码区'
                                break;
                            }
                            case 12: {
                                result = '打码区'
                                break;
                            }
                            default: {
                                result = '未知'
                                break;
                            }
                        }
                        break;
                    }
                    case "抓命令1": {
                        switch (value) {
                            case 0: {
                                result = "";
                                break;
                            }
                            default: {
                                result = "上料车No" + value;
                                break;
                            }
                        }
                        break;
                    }
                    case "抓命令2": {
                        switch (value) {
                            case 1: {
                                result = '车床1'
                                break;
                            }
                            case 2: {
                                result = '缓存台1'
                                break;
                            }
                            case 3: {
                                result = '缓存台2'
                                break;
                            }
                            case 4: {
                                result = '车床2'
                                break;
                            }
                            case 5: {
                                result = '缓存台3'
                                break;
                            }
                            case 6: {
                                result = '缓存台4'
                                break;
                            }
                            case 7: {
                                result = '车床3'
                                break;
                            }
                            case 8: {
                                result = '缓存台5'
                                break;
                            }
                            case 9: {
                                result = '缓存台6'
                                break;
                            }
                            case 10: {
                                result = '孔深测量'
                                break;
                            }
                            case 11: {
                                result = '扫码区'
                                break;
                            }
                            case 12: {
                                result = '打码区'
                                break;
                            }
                            default: {
                                break;
                            }
                        }
                        break;
                    }
                    case "放命令1": {
                        switch (value) {
                            case 0: {
                                result = "";
                                break;
                            }
                            default: {
                                result = '下料车No' + value
                                break;
                            }
                        }
                        break;
                    }
                    case "放命令2": {
                        switch (value) {
                            case 1: {
                                result = '车床1'
                                break;
                            }
                            case 2: {
                                result = '缓存台1'
                                break;
                            }
                            case 3: {
                                result = '缓存台2'
                                break;
                            }
                            case 4: {
                                result = '车床2'
                                break;
                            }
                            case 5: {
                                result = '缓存台3'
                                break;
                            }
                            case 6: {
                                result = '缓存台4'
                                break;
                            }
                            case 7: {
                                result = '车床3'
                                break;
                            }
                            case 8: {
                                result = '缓存台5'
                                break;
                            }
                            case 9: {
                                result = '缓存台6'
                                break;
                            }
                            case 10: {
                                result = '孔深测量'
                                break;
                            }
                            case 11: {
                                result = '扫码区'
                                break;
                            }
                            case 12: {
                                result = '打码区'
                                break;
                            }
                            default: {
                                break;
                            }
                        }
                        break;
                    }
                    case "位置": {
                        switch (value) {
                            case 1: {
                                result = '车床1'
                                break;
                            }
                            case 2: {
                                result = '缓存台1'
                                break;
                            }
                            case 3: {
                                result = '缓存台2'
                                break;
                            }
                            case 4: {
                                result = '车床2'
                                break;
                            }
                            case 5: {
                                result = '缓存台3'
                                break;
                            }
                            case 6: {
                                result = '缓存台4'
                                break;
                            }
                            case 7: {
                                result = '车床3'
                                break;
                            }
                            case 8: {
                                result = '缓存台5'
                                break;
                            }
                            case 9: {
                                result = '缓存台6'
                                break;
                            }
                            case 10: {
                                result = '孔深测量'
                                break;
                            }
                            case 11: {
                                result = '车床1'
                                break;
                            }
                            case 12: {
                                result = '缓存台1'
                                break;
                            }
                            case 13: {
                                result = '缓存台2'
                                break;
                            }
                            case 14: {
                                result = '车床2'
                                break;
                            }
                            case 15: {
                                result = '缓存台3'
                                break;
                            }
                            case 16: {
                                result = '缓存台4'
                                break;
                            }
                            case 17: {
                                result = '车床3'
                                break;
                            }
                            case 18: {
                                result = '缓存台5'
                                break;
                            }
                            case 19: {
                                result = '缓存台6'
                                break;
                            }
                            case 20: {
                                result = '孔深测量'
                                break;
                            }
                            case 30: {
                                result = '上料车'
                                break;
                            }
                            case 41: {
                                result = '成品车'
                                break;
                            }
                            case 42: {
                                result = 'NG车'
                                break;
                            }
                            case 51: {
                                result = '扫码区'
                                break;
                            }
                            case 52: {
                                result = '打码区'
                                break;
                            }
                            case 61: {
                                result = '扫码区'
                                break;
                            }
                            case 62: {
                                result = '打码区'
                                break;
                            }
                            default: {
                                break;
                            }
                        }
                        break;
                    }
                    default: {
                        break;
                    }
                }
                return result;
            },
        },
        mounted() {
            this.GetTodayData();
            setInterval(() => {
                this.GetTodayData();
            },2000)
        }
    })
</script>

